package com.breakfast.fun.base;

import android.app.Dialog;
import android.content.Context;

import com.breakfast.fun.util.Api;
import com.breakfast.fun.util.DialogUtil;

import java.util.Map;

/**
 * Created by hp on 2016/8/13.
 */
public abstract class BasePresenter<M, V> {

    public Context context;
    public M model;
    public V view;
    public RxManager rxManager = new RxManager();
    public Map<String, String> params = Api.getInstance().getBaseParams();

    protected DialogUtil mDialogUtil;
    protected Dialog mDialog;

    public void setVM(Context context, V v, M m) {
        this.context = context;
        mDialogUtil = new DialogUtil(context);
        this.view = v;
        this.model = m;
        this.onStart();
    }

    protected void showLoadingDialog(boolean isCanClose) {
        if (mDialog != null) {
            if (mDialog.isShowing()) {
                mDialog.dismiss();
            }
        }
        mDialog = mDialogUtil.getWaitDialog("加载中...", isCanClose);
    }

    protected void hideLoadingDialog() {
        if (mDialog != null) {
            if (mDialog.isShowing()) {
                mDialog.dismiss();
            }
        }
    }

    public abstract void onStart();

    public void onDestroy() {
        rxManager.clear();
    }

}
